LEADTOOLS Annotations (Leadtools.Annotations assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
Save(String,AnnContainer[],AnnCodecsFormat) Method
See Also 
Leadtools.Annotations Namespace > AnnCodecs Class > Save Method : Save(String,AnnContainer[],AnnCodecsFormat) Method



fileName
The output file name.
containers
An array of AnnContainer containing the objects to be saved.
format
An AnnCodecsFormat value that specifies the annotation format to use when saving.
fileName
The output file name.
containers
An array of AnnContainer containing the objects to be saved.
format
An AnnCodecsFormat value that specifies the annotation format to use when saving.
Saves an array of AnnContainer to a multipage annotation disk file

Syntax

Visual Basic (Declaration) 
Overloads Public Sub Save( _
   ByVal fileName As String, _
   ByVal containers() As AnnContainer, _
   ByVal format As AnnCodecsFormat _
) 
Visual Basic (Usage)Copy Code
Dim instance As AnnCodecs
Dim fileName As String
Dim containers() As AnnContainer
Dim format As AnnCodecsFormat
 
instance.Save(fileName, containers, format)
C# 
public void Save( 
   string fileName,
   AnnContainer[] containers,
   AnnCodecsFormat format
)
C++/CLI 
public:
void Save( 
   String^ fileName,
   array<AnnContainer^>^ containers,
   AnnCodecsFormat format
) 

Parameters

fileName
The output file name.
containers
An array of AnnContainer containing the objects to be saved.
format
An AnnCodecsFormat value that specifies the annotation format to use when saving.

Example

Visual BasicCopy Code
Public Sub AnnCodecs_Save2()
    ' create three  annotation containers
    ' The first container contains a rectangle object
    Dim container0 As New AnnContainer()
    Dim rectObj As New AnnRectangleObject()
    rectObj.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel)
    rectObj.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel))
    rectObj.Brush = Nothing
    container0.Objects.Add(rectObj)

    ' The second container contains a line object
    Dim container1 As New AnnContainer()
    Dim lineObj As New AnnLineObject()
    lineObj.StartPoint = New AnnPoint(100, 100, AnnUnit.Pixel)
    lineObj.EndPoint = New AnnPoint(200, 200, AnnUnit.Pixel)
    lineObj.Pen = New AnnPen(Color.Red, New AnnLength(1, AnnUnit.Pixel))
    container1.Objects.Add(lineObj)

    ' The third container contains a ellipse object
    Dim container2 As New AnnContainer()
    Dim ellipseObj As New AnnEllipseObject()
    ellipseObj.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel)
    ellipseObj.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel))
    ellipseObj.Brush = Nothing
    container2.Objects.Add(ellipseObj)

    ' create a file to save both annotation containers
    Dim annFileName As String = Path.GetTempFileName()

    ' create a new AnnCodecs class
    Dim codecs As New AnnCodecs()

    ' save both AnnContainers into the stream
    codecs.Save(annFileName, container0, AnnCodecsFormat.Xml, 1, AnnCodecsSavePageMode.Overwrite)
    codecs.Save(annFileName, container1, AnnCodecsFormat.Xml, 2, AnnCodecsSavePageMode.Insert)

    ' Now load both containers from the stream, and verify that there are two containers
    Dim containersTwo() As AnnContainer = codecs.Load(annFileName)
    MessageBox.Show(String.Format("After Load: there should be 2 containers.  Total number of containers: {0}", containersTwo.Length))

    ' Add another container, and save to the stream
    Dim containersNew(containersTwo.Length) As AnnContainer
    Array.Copy(containersTwo, containersNew, containersTwo.Length)
    containersNew(2) = container2

    codecs.Save(annFileName, containersNew, AnnCodecsFormat.Xml)

    ' Load and verify that there are three containers
    Dim containersThree() As AnnContainer = codecs.Load(annFileName)
    MessageBox.Show(String.Format("After Load: there should be 3 containers.  Total number of containers: {0}", containersThree.Length))
End Sub
C#Copy Code
public void AnnCodecs_Save2()
{
   // create three  annotation containers
   // The first container contains a rectangle object
   AnnContainer container0 = new AnnContainer();
   AnnRectangleObject rectObj = new AnnRectangleObject();
   rectObj.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel);
   rectObj.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel));
   rectObj.Brush = null;
   container0.Objects.Add(rectObj);

   // The second container contains a line object
   AnnContainer container1 = new AnnContainer();
   AnnLineObject lineObj = new AnnLineObject();
   lineObj.StartPoint = new AnnPoint(100, 100, AnnUnit.Pixel);
   lineObj.EndPoint = new AnnPoint(200, 200, AnnUnit.Pixel);
   lineObj.Pen = new AnnPen(Color.Red, new AnnLength(1, AnnUnit.Pixel));
   container1.Objects.Add(lineObj);

   // The third container contains a ellipse object
   AnnContainer container2 = new AnnContainer();
   AnnEllipseObject ellipseObj = new AnnEllipseObject();
   ellipseObj.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel);
   ellipseObj.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel));
   ellipseObj.Brush = null;
   container2.Objects.Add(ellipseObj);

   // create a file to save both annotation containers
   string annFileName = Path.GetTempFileName();

   // create a new AnnCodecs class
   AnnCodecs codecs = new AnnCodecs();

   // save both AnnContainers into the stream
   codecs.Save(annFileName, container0, AnnCodecsFormat.Xml, 1, AnnCodecsSavePageMode.Overwrite);
   codecs.Save(annFileName, container1, AnnCodecsFormat.Xml, 2, AnnCodecsSavePageMode.Insert);

   // Now load both containers from the stream, and verify that there are two containers
   AnnContainer[] containersTwo = codecs.Load(annFileName);
   MessageBox.Show(String.Format("After Load: there should be 2 containers.  Total number of containers: {0}", containersTwo.Length));

   // Add another container, and save to the stream
   AnnContainer[] containersNew = new AnnContainer[containersTwo.Length + 1];
   Array.Copy(containersTwo, containersNew, containersTwo.Length);
   containersNew[2] = container2;

   codecs.Save(annFileName, containersNew, AnnCodecsFormat.Xml);

   // Load and verify that there are three containers
   AnnContainer[] containersThree = codecs.Load(annFileName);
   MessageBox.Show(String.Format("After Load: there should be 3 containers.  Total number of containers: {0}", containersThree.Length));
}

Remarks

This method saves the entire array of AnnContainer as a multipage annotation file, with each page corresponding to one of the AnnContainer. If fileName already exists, it will be overwritten. If containers contain many AnnContainer, then this method will create the multipage annotation file much faster than repeated calls to Save(String,AnnContainer,AnnCodecsFormat,Int32,AnnCodecsSavePageMode)

This method only supports the AnnCodecsFormat.Xml format. All other AnnCodecsFormat are not supported.

For more information, refer to Annotation Files.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Leadtools.Annotations requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features